/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.manager.phase;

import ru.jSkyRoom.bridge.ModBridge;
import ru.jSkyRoom.manager.ModExporter;
import ru.jSkyRoom.manager.ModManager;
import skyproc.Mod;
import skyproc.ModListing;
import skyproc.exceptions.BadMod;
import skyproc.exceptions.MissingMaster;

/**
 *
 * @author Rakev
 */
public class SelectActiveMode {

    public ImportingModPhase beginCreatingMod(String author, String newModName) {
        ModListing modListing = new ModListing(newModName);
        Mod patch = new Mod(modListing);
        patch.setAuthor(author);
        ModBridge modBridge = new ModBridge(patch);
        getModManager().setActiveMod(modBridge);
        return new ImportingModPhase();
    }

    public ImportingModsForEditingModPahase beginEditingMod(String modName, String pathToSave) throws BadMod, MissingMaster {
        if (pathToSave.equals(ModManager.getInstance().getPathToData())) {
            throw new IllegalArgumentException("pathToSave must not be equals PathToData");
        }
        ModExporter.getInstance().setPathToSave(pathToSave);
        createTempModForPermitModloading();
        return new ImportingModsForEditingModPahase(modName);
    }

    private void createTempModForPermitModloading() {
        ModListing modListing = new ModListing("temp");
        Mod patch = new Mod(modListing);
        ModBridge tempModBridge = new ModBridge(patch);
        getModManager().setActiveMod(tempModBridge);
    }

    private ModManager getModManager() {
        return ModManager.getInstance();
    }
}
